const db = wx.cloud.database()
const firstSwiperImagesCollection = db.collection('firstSwiperImages')

const commoditiesCollection = db.collection('commodities')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    firstSwiperImagesCollection.get().then(res => {
      console.log("成功读取三张轮播图", res.data)
      this.setData({
      firstSwiperImages: res.data
      })
      })
      commoditiesCollection.get().then(res => {
        console.log("成功读取八个商品类别",res.data)
        this.setData({
        commodities:res.data})

      })
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  },
  navigateToCommodities: function (e) {     
    var goodsID = e.currentTarget.dataset.gid; 
    var typeID = e.currentTarget.dataset.tid;     
    var id = e.currentTarget.dataset.id;     
    console.log("即将跳转到第", typeID, "类的第", goodsID, "个商 品详情")    
     wx.navigateTo({      
        url: 'commodities/commodities?typeID=' + typeID + '&goodsID=' + goodsID + '&id=' + id,    
       })  
       },
       switchGoodsTab: function (e) {     
         var typeID = e.currentTarget.dataset.tid; 
         var id = e.currentTarget.dataset.id;     
         console.log("即将跳转到第", typeID, "类的商品详情")     
         wx.navigateTo({       
           url: 'goodsTab/goodsTab?typeID=' + typeID+'&id='+id,     
          }) },



          




          
         
       
          
})